﻿using System.Collections.Generic;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.GamePlay;
using NetProtocol.POD;

namespace IQIGame.Onigao.Logic
{
    public class BattleTeam : IPODFactory
    {
        public int teamIndex = -1;
        public List<Unit> units = new List<Unit>();
        public BattleUnitPOD subtitute;
        
        public BattleTeam Initialize(int nTeamIndex)
        {
            this.teamIndex = nTeamIndex;
            
            return this;
        }

        public IPOD GeneratePOD()
        {
            var rPOD = new BattleTeamViewPOD()
            {
                teamIndex = (byte)this.teamIndex,
            };
            for (int j = 0; j < this.units.Count; j++)
            {
                rPOD.units.Add(this.units[j].GeneratePOD() as BattleUnitViewPOD);
            }
        
            return rPOD;
        }
        
        public static int GetTargetTeamIndex(int nCurIndex, ETargetRelation rRelation)
        {
            if (rRelation == ETargetRelation.Friend)
            {
                return nCurIndex;
            }
            return nCurIndex == BattleConst.TeamRedIndex ? BattleConst.TeamBlueIndex : BattleConst.TeamRedIndex;
        }
    }
}